<?php

namespace App\Http\Middleware;

use App\Model\Role;
use Closure;
use App\Model\User;

class HasRole
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        //获取当前访问的路由
        $route = \Route::current()->getActionname();

        //获取当前用户拥有的权限
        $perms = session()->get('per');

        //判断是否为超级管理员
        if(session()->get('superAdmin')){
            return $next($request);
        }

        //判断当前访问是否有权限
        if (in_array($route, $perms)) {
            return $next($request);
        }else{
            return redirect('noaccess');
        }
    }
}
